package com.tjl.controller;

import com.tjl.bean.User;
import com.tjl.dao.UserDao_Imp;
import com.tjl.view.View;

public class control {
    public static void main(String[] args) {
        while (true) {
        //登录界面
        User user = View.indexView();
        UserDao_Imp userDao_imp = new UserDao_Imp();

            int user_type = userDao_imp.login(user);
            switch(user_type){
                case -1:
                    System.out.println("系统无此人！！！");
                    break;
                case 1:
                    System.out.println("管理员登录成功");
                    managerServer();
                    break;
                case 2:
                    System.out.println("学生登录成功");
                    studentServer();
                    break;
                default:
                    break;
            }
        }
    }

    private static void managerServer(){
        //管理员登录菜单
        UserDao_Imp userDao_imp =new UserDao_Imp();
        boolean flag;
        while(true) {
            int item = View.managerMenuView();
            switch (item){
                case 0:
                    System.exit(-1);
                    break;
                case 1:
                    User user = View.addMenuView();
                    flag = userDao_imp.insert(user);
                    System.out.println(flag?"add success":"add fail");
                    break;
                case 2:
                    String toBeDeletedUserName = View.deleteMenuView();
                    flag = userDao_imp.delete(toBeDeletedUserName);
                    System.out.println(flag?"delete success":"delete fail");
                    break;
                case 3:
                    user = View.UpdateMenuView();
                    flag = userDao_imp.update(user);
                    System.out.println(flag?"update success":"update fail");
                    break;
                case 4:
                    String toBeSelectedUserName = View.selectMenuView();
                    user = userDao_imp.select(toBeSelectedUserName);
                    System.out.println(user);
                    break;
                default:
                    break;
            }
        }
    }

    private static void studentServer(){
        //学生登陆菜单
        User user = new User();
        UserDao_Imp userDao_imp  = new UserDao_Imp();
        while(true){
            int item = View.studentMenuView();
            switch (item){
                case 0:
                    System.exit(-1);
                case 1:
                    String toBeSelectedUserName = View.selectMenuView();
                    System.out.println(userDao_imp.select(toBeSelectedUserName));
            }
        }
    }
}
